<template>
    <div>
        <h1>用户登录</h1>
        <table class="table">
            <tbody>
                <tr>
                    <th>账号</th>
                    <th>
                        <input type="text" v-model="data.UserZH">
                    </th>
                </tr>
                <tr>
                    <th>密码</th>
                    <th>
                        <input type="password" v-model="data.UserPwd">
                    </th>
                </tr>
                <tr>
                    <th colspan="2">
                        <input type="button" value="登录" @click="Add">
                    </th>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
    import { ref,onMounted } from 'vue';
    import axios from 'axios';
    import { useRouter } from 'vue-router';
    const Router = useRouter()
    const data = ref({
    "UserZH": "",
    "UserPwd": "",
    })
    const Add=()=>{
        if(data.value.UserZH==""){
            alert('账号不能为空')
            return
        }
        if(data.value.UserPwd==""){
            alert('密码不能为空')
            return
        }
        axios.get("https://localhost:7018/api/User/Login",{params:data.value}).then(res=>{
            if(res.data.Id==-1){
                alert('没有此账号!!')
            }
            else if(res.data.Id==-2){
                alert('密码错误!!')
            }
            else if(res.data.Id>0){
                alert('登录成功')
                Router.push({path:"/ShowUser"})
            }
            else{
                alert('登录失败');
            }
        })
    }
</script>

<style scoped>

</style>